#!coding:utf-8

## init.py
## 初始化meta节点: management(管理根节点), operation(操作根节点)
## 并将两者的uuid属性写入配置文件settiongs.conf中

from py2neo import Node, Relationship, NodeSelector
import ConfigParser
import string, os, sys
import uuid
from common.GraphDB import graphDB

tx = graphDB.begin()
management, operation = Node('META'), Node('META')
## 借由uuid库生成节点唯一ID
## 注意:uuidx()函数生成的结果为UUID类复杂类型, 需要转换成字符串简单类型
management['uuid'], operation['uuid'] = str(uuid.uuid1()), str(uuid.uuid1())
management['title'], operation['title'] = 'management', 'operation'
tx.create(management)
tx.create(operation)

tx.commit()
 
## 写入配置文件
configFile = 'settings.conf'
cp = ConfigParser.ConfigParser()
cp.read(configFile)
cp.set('meta', 'management_uuid', management['uuid'])
cp.set('meta', 'operation_uuid', operation['uuid'])
cp.write(open(configFile, 'w'))
